<template>
	<view class="viewcontent">
		<view class="viewcontenthead">
			<view class="fl" @click="$UTILS.goBack(1)"></view>
			<view class="fr" style="color: #fdf5fa;"> 清点明细</view>
			<view class="leftitem">
			</view>
		</view>

		<view class="viewcontenmes">
			<view class="contentwrap">
				<view class="contentitems" v-for="(item,index) in datalist" :key="index">
				<!-- <view class="contentitems" v-for="(item,index) in datalist" :key="index"
				:style="item.equipmentStatus==0?'border: 2px solid #ff6f6f;':'border: 2px solid green'"> -->
					<view class="itemfirst">序号：{{index+1}}</view>
					<view class="itemsecond">
						<view class="itemseconditem">
							<view>物资名称：{{item.equipmentName}}</view>
						</view>
					</view>
					<view class="itemfoued">
						<view class="itemseconditem">
							<view>物资编码：{{item.equipmentCode}}</view>
						</view>
					</view>
					<view class="itemfoued">
						<view class="itemseconditem">
							<view>RFID：{{item.equipmentRfid}}</view>
						</view>
					</view>
					<view class="itemthird">
						<view class="itemthirditem">
							<view class="itemthirditemfuc">
								状态：
								<!--{{item.equipmentStatus}}-->
								<uni-data-select style="height: 50rpx;width: 150rpx;" name="select" :localdata="range"
									v-model="item.equipmentStatus" @change="change(item,$event)">
								</uni-data-select>
							</view>
						</view>
						<view class="itemthirditem">
							<view class="beizhu"><text>备注：</text>
								<uni-easyinput style="width: 200rpx;" v-model="item.describe"
									placeholder="请输入内容" @input="input(item)"></uni-easyinput>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>

		<keyboard-listener @keydown="onKeydown"></keyboard-listener>
		<keyboard-listener @keyup="onKeyup"></keyboard-listener>
		<myLoading v-if="loading" style="position: absolute;z-index: 9;"></myLoading>
	</view>
</template>

<script>
	import keyboardListener from '../../../components/uniapp-keyboard-listener/src/keyboard-listener.vue'
	let andoridModule = uni.requireNativePlugin('seuic-uhf');
	// #ifdef APP-PLUS
	// const pda = uni.requireNativePlugin("PDAModule");
	// const tone = uni.requireNativePlugin("ToneModule");
	// var log = uni.requireNativePlugin("LogModule")
	// #endif
	export default {
		components: {
			keyboardListener
		},
		onLoad(option) {
			let data = JSON.parse(option.data)
			this.datalist = data.equipmentList
			this.taskCode = data.taskCode
		},
		data() {
			return {
				datalist: [],
				taskCode: '',
				scanBtnTimeOutCount: 0,
				scanBtnClickDownFlag: false,
				pdaStart: false,
				loading: false,
				range: [{
						value: 1,
						text: "正常"
					},
					{
						value: 0,
						text: "缺失"
					},
				],
				lastQueryTimestamp: 0,
				rfidList: []

			}
		},
		onHide() {
			this.loading = true
			let data = this.$UTILS.getInventorysupplies().map(item => {
				if (item.taskCode == this.taskCode) {
					item.equipmentList = this.datalist
					return item
				} else {
					return item
				}
			})
			setTimeout(() => {
				this.loading = false
				this.$UTILS.setInventorysupplies(data)
			}, 1000)

		},
		onUnload() {
			this.loading = true
			let data = this.$UTILS.getInventorysupplies().map(item => {
				if (item.taskCode == this.taskCode) {
					item.equipmentList = this.datalist
					return item
				} else {
					return item
				}
			})
			setTimeout(() => {
				this.loading = false
				this.$UTILS.setInventorysupplies(data)
			}, 1000)


		},
		methods: {
			change(item, e) {
				switch (e) {
					case 0:
						item.equipmentStatus = 0;
						break;
					case 1:
						item.equipmentStatus = 1;
						break;
					default:
						item.equipmentStatus = 2;
						break;
				}
			},
			input(item) {},

			onKeydown(e) {
				if (e.keyCode == 123) {
					const now = Date.now();
					// 节流间隔，1000 毫秒
					const throttleDuration = 1000;
					if (now - this.lastQueryTimestamp < throttleDuration) {
						// 如果当前时间与最后一次执行的时间差小于节流间隔，则不执行
						return;
					}
					this.lastQueryTimestamp = now;
					andoridModule.inventoryStart((e) => {
						if (e != '未寻到') {
							let jsonResult = JSON.parse(JSON.stringify(e));
							jsonResult.forEach(item => {
								if (this.rfidList.indexOf(item.id) == -1) {
									this.rfidList.push(item.id)
								}
							})
						} else {
							this.templedata = e
						}
					});
				}
			},
			onKeyup(e) {
				console.log(this.rfidList)
				andoridModule.inventoryStop((e) => {
					this.templedata = e
				});
				this.datalist = this.datalist.map(item => {
					if (this.rfidList.indexOf(item.equipmentRfid) != -1) {
						item.equipmentStatus = 1
						return item
					}
					return item
				})


			},
			processData(result) {
				let jsonResult = JSON.parse(result);
				if (this.rfidList.indexOf(jsonResult.epc) == -1) {
					this.rfidList.push(jsonResult.epc)
				}

			},

		}
	}
</script>

<style lang="scss" scoped>
	.viewcontent {
		display: flex;
		flex-direction: column;
		width: 100%;
		height: 100vh;
		box-sizing: border-box;
		padding-top: 55rpx;

		.viewcontenthead {
			width: 100%;
			height: 5%;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.fl {
				width: 100rpx;
				height: 10vh;
				line-height: 10vh;
				background: url("/static/right-arrow.png") no-repeat center;
				background-size: 14%;
				transform: rotate(180deg);
				cursor: pointer; // 增加鼠标指针样式
			}

			.fr {
				cursor: pointer; // 增加鼠标指针样式
			}

			.leftitem {
				width: 100rpx;
				display: flex;
				justify-content: center;
				z-index: 999;
			}
		}


		.viewcontenmes {
			width: 100%;
			height: 95%;

			.contentwrap {
				width: 100%;
				height: 100%;
				box-sizing: border-box;
				padding-left: 15rpx;
				padding-right: 15rpx;
				padding-top: 25rpx;

				.contentitems {
					width: 100%;
					height: 350rpx;
					border: 1px solid #FFFFFF;
					border-radius: 15rpx;
					margin-bottom: 25rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #FFFFFF;
					font-size: 16px;

					.itemfirst {
						box-sizing: border-box;
						padding-left: 15rpx;
						width: 100%;
						height: 20%;
						display: flex;
						align-items: center;
					}

					.itemfoued {
						box-sizing: border-box;
						padding-left: 15rpx;
						width: 100%;
						height: 20%;
						display: flex;
						align-items: center;

						.itemseconditem {
							width: 100%;
							height: 100%;
							display: flex;
							align-items: center;
							flex-direction: row;
							overflow: hidden;
							white-space: nowrap;
							text-overflow: ellipsis;

							view {
								overflow: hidden;
								white-space: nowrap;
								text-overflow: ellipsis;
							}
						}
					}

					.itemsecond {
						width: 100%;
						height: 20%;
						box-sizing: border-box;
						padding-left: 15rpx;
						display: flex;
						flex-direction: row;

						.itemseconditem {
							width: 100%;
							height: 100%;
							display: flex;
							align-items: center;
							flex-direction: row;
							overflow: hidden;
							white-space: nowrap;
							text-overflow: ellipsis;

							view {
								overflow: hidden;
								white-space: nowrap;
								text-overflow: ellipsis;
							}
						}
					}

					.itemthird {
						width: 100%;
						height: 20%;
						box-sizing: border-box;
						padding-left: 15rpx;
						padding-bottom: 8rpx;
						display: flex;
						align-items: center;
						flex-direction: row;

						.itemthirditem {
							width: 50%;
							height: 100%;
							display: flex;
							align-items: center;

							.itemthirditemfuc {
								display: flex;
								flex-direction: row;
							}

							.beizhu {
								display: flex;
								flex-direction: row;
								justify-content: center;
							}
						}
					}
				}
			}
		}
	}

	::v-deep .uni-select__input-placeholder {
		color: rgba(250, 249, 249, 0.8) !important;
	}

	::v-deep .uni-select__input-text {
		color: rgba(250, 249, 249, 0.8) !important;
	}


	::v-deep .uni-input-input {
		color: rgba(250, 249, 249, 0.8) !important;
	}

	::v-deep .uni-easyinput__content {
		min-height: 26rpx;
	}

	::v-deep .uni-select__selector {
		color: rgba(0, 0, 0, 0.8) !important;
	}

	::v-deep .uni-icons {
		display: none;
	}
	::v-deep .uni-select{
		height: 43rpx;
	}
</style>
